<template>
  <div class="container">
    <div class="top-nav">
      <van-icon name="arrow-left" @click="$router.back()"/>
      <van-search 
        shape="round" 
        show-action 
        background="transparent"
        v-model="value"
        @search="onSearch"
      >
        <template #action>
          <div @click="onSearch">搜索</div>
        </template>
      </van-search>
    </div>
    <div class="history">
      <div class="history-title">
        <span style="font-weight: 600;">搜索历史</span>
        <van-icon name="delete-o" @click="deleteHis"/>
      </div>
      <div class="history-content">
        <div v-for="item in historyList" class="history-item">
          {{ item }}
        </div>
      </div>
    </div>
 </div>
</template>

<script>
import { ref,reactive, onMounted } from 'vue'
export default {
  name:'',
  setup() {
    let value = ref('')
    let historyList = reactive(
      JSON.parse(sessionStorage.getItem("historyList")) || []
    )
    const onSearch = () => {
      historyList.push(value.value)
      sessionStorage.setItem("historyList",JSON.stringify(historyList))
    } 
    const deleteHis = () => {

    }
    return {
      value,
      historyList,
      onSearch,
      deleteHis
    } 
  }
}
</script>

<style scoped lang="less">
.container {
  width: 100vw;
  height: 100vh;
  background-color: #f5f5f5;
}
.top-nav {
  height: 1rem;
  display: flex;
  align-items: center;
  padding: 0 .2rem;
  .van-icon {
    font-size: .6rem;
    color: #666;
  }
  ::v-deep .van-search {
    flex: 1;
    .van-search__content  {
      background-color: #fff;
    }
  }
}
.history {
  padding: .2rem .3rem;
.history-title {
  display: flex;
  justify-content: space-between;
  .van-icon {
    font-size: .4rem;
    color: #666;
  }
}
.history-content {
  padding: .2rem;
  display: flex;
  flex-wrap: wrap;
  .history-item {
    padding: .1rem .3rem;
    border-radius: .3rem;
    background: #fff;
    margin: .1rem;
  }
}
}
</style>
